//
//  BeadsApi.m
//  Api
//
//  Created by CPX on 2018/11/1.
//  Copyright © 2018 CPX. All rights reserved.
//

#import "BeadsApi.h"
#import "YYModel.h"
#import "LanguageManager.h"
@implementation BeadsApi



+ (void)getDailyProverArrayWithModelClass:(Class)modelClass
                           NormalResponse:(void(^)(NSInteger status, id data, NSMutableArray *array))normalResponse
                        exceptionResponse:(void(^)(NSError *error))exceptionResponse{

    
    
    [self getJsonArrayWithAction:@"daily_proverb" Param:nil modelClass:[NSObject class] normalResponse:normalResponse exceptionResponse:exceptionResponse];
    
    
    
    
}

+ (void)getJsonArrayWithAction:(NSString *)action
                                Param:(NSDictionary *)param
                           modelClass:(Class)modelClass
                       normalResponse:(void(^)(NSInteger status, id data, NSMutableArray *array))normalResponse
                    exceptionResponse:(void(^)(NSError *error))exceptionResponse {
    
    
    NSString *url = [NSString stringWithFormat:@"%@%@",RootURL,action];
    [NetworkManagerV3 GETWithURL:url header:[self header] params:param success:^(id response) {
        if([self dealWithResponse:response]){
            NSArray * data = response[@"data"];
            NSInteger status = [response[@"code"] integerValue];
            NSMutableArray *returnArr = [NSMutableArray array];
            
            if ([data isKindOfClass:[NSArray class]]) {
                NSMutableArray *returnArr = [NSMutableArray array];
                
                if (modelClass == [NSString class]) {
                    for (id dic in data) {
                        [returnArr addObject:dic];
                    }
                    normalResponse(status, data, returnArr);
                } else {
                    for (id dic in data) {
                        
                        [returnArr addObject:[modelClass yy_modelWithDictionary:dic]];
                    }
                    normalResponse(status, data, returnArr);
                }
                
            } else {
                normalResponse(status, data, [@[] mutableCopy]);
            }
            
        }
        else{
            NSError *error = [NSError errorWithDomain:APPResponseError code:10001 userInfo:response];
            exceptionResponse(error);
        }
    } failure:^(NSError *error) {
        exceptionResponse(error);
    }];
    
    
}


+ (NSMutableDictionary*)header{
    return [NSMutableDictionary dictionaryWithObjectsAndKeys:[BaseApi standard].language,@"language",@"Token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NSwiZXhwIjoxNTQxODM4MDg5fQ.--57_E3aQXS0AB2CON5rqIk8916firPuEMwGfNfFWWw",@"Authorization",[BaseApi standard].version,@"version", nil];
}

@end
